package com.academia.dataAccess;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import com.academia.model.User;

public class LoginDAO {
	
	ArrayList<User> users;
	
	public ArrayList<User> login(String userName,String pass){
		Connection conexion = DBConnect.getInstance().connect();
		String select = "SELECT userName,pass from users where userName = ? and pass = ?";
		users = new ArrayList<User>();
		
		try{
			PreparedStatement preparedStatement = conexion.prepareStatement(select);
			preparedStatement.setString(1, userName);
			preparedStatement.setString(1, pass);
			
			ResultSet rs = preparedStatement.executeQuery();
			
			while(rs.next()){
				User user = new User();
				user.setUser(rs.getString("userName"));
				user.setPass(rs.getString("pass"));
				users.add(user);
				
			}
			
			
		}catch(SQLException e){
			e.printStackTrace(); 
		}
		
		try {
			conexion.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return users;
		
		
		
		
	}

}
